package com.kool.kadmin.system.controller;

import com.kool.kadmin.common.bean.ListResult;
import com.kool.kadmin.common.bean.PageListResult;
import com.kool.kadmin.common.bean.Result;
import com.kool.kadmin.system.bean.SysAutDo;
import com.kool.kadmin.system.request.*;
import com.kool.kadmin.system.service.AutService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 权限管理
 *
 * @author luyu
 */
@RestController
@Slf4j
public class AutController {
    @Resource
    private AutService autService;

    /**
     * 增加权限
     *
     * @param request
     * @return
     */
    @RequestMapping("/aut/add")
    public Result add(@Valid @RequestBody AddAutReq request) {
        return autService.add(request);
    }

    /**
     * 修改权限
     *
     * @param request
     * @return
     */
    @RequestMapping("/aut/modify")
    public Result modify(@Valid @RequestBody ModifyAutReq request) {
        return autService.modify(request);
    }

    /**
     * 删除权限
     *
     * @param request
     * @return
     */
    @RequestMapping("/aut/delete")
    public Result delete(@Valid @RequestBody DeleteAutReq request) {
        return autService.delete(request);
    }

    /**
     * 分页查询权限列表
     *
     * @return
     */
    @RequestMapping("/aut/get_page")
    public PageListResult<SysAutDo> getPage(@Valid @RequestBody GetAutPageReq request) {
        return autService.getPage(request);
    }

    /**
     * 查询所有权限
     *
     * @return
     */
    @RequestMapping("/aut/get_all_auth")
    public ListResult<SysAutDo> getAllAuth() {
        return autService.getAllAuth();
    }

    /**
     * 角色授权
     *
     * @return
     */
    @RequestMapping("/aut/aut_role")
    public Result autRole(@Valid @RequestBody AutRoleReq request) {
        return autService.autRole(request);
    }

    /**
     * 绑定菜单权限
     *
     * @return
     */
    @RequestMapping("/aut/bind_menu_aut")
    public Result bindMenuAut(@Valid @RequestBody BindMenuAutReq request) {
        return autService.bindMenuAut(request);
    }

    /**
     * 查询角色已授权权限
     *
     * @return
     */
    @RequestMapping("/aut/get_role_aut")
    public ListResult<SysAutDo> getRoleAut(@Valid @RequestBody GetRoleAutsReq request) {
        return autService.getRoleAut(request);
    }
}
